#include<bits/stdc++.h>
using namespace std;
int t,n,a[100005],tmp,cnt,sum;
bool vis[100005];
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>t;
    for(int i=1;i<=t;i++){
        sum=0;
        cnt=0;
        cin>>n;
        for(int j=1;j<=n;j++){
            cin>>a[j];
        }
        for(int j=1;j<=n;j++){
            for(int k=1;k<=n-j;k++){
                if(j==1&&k==2){
                    break;
                }
                if(sum<cnt){
                    sum=cnt;
                }
                cnt=0;
                for(int l=k+j;l<=n;l+=j-bool(j-1)){
                    tmp=l-j;
                    if(a[tmp]==a[l]){
                        if(vis[tmp-1]&&a[tmp-2]==a[tmp+1]){
                            cnt+=a[tmp-2];
                        }
                        cnt+=a[tmp];
                        vis[l]=1;
                    }
                }
            }
        }
        if(sum<cnt){
            sum=cnt;
        }
        cout<<sum<<"\n";
    }
}
